package com.ljkj.cordial.chat.bean;

import com.lanjiu.lib.imclient.ims.IMSContacts;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 图片/视频/文本/语音/表情/附件
 */
public class MsgType {

    public static final int Picture = 1;

    public static final int Video = 2;
    public static final int Voice = 3;
    public static final int Expression = 4;
    public static final int Text = 5;
    public static final int ANNEX = 6;
    public static final int Read_Finish = 7;
    public static final int History_Time = 8;
    public static final int Del_Chat_Msg = 9;


    public static int translateChatType(int thisMsgType) {
        switch (thisMsgType) {
            case Picture:
                return IMSContacts.MsgContentType.PICTURE;
            case Video:
                return IMSContacts.MsgContentType.VIDEO;
            case Voice:
                return IMSContacts.MsgContentType.VOICE;
            case Expression:
            case Text:
                return IMSContacts.MsgContentType.TEXT;
            case ANNEX:
                return IMSContacts.MsgContentType.FILE;
        }
        return IMSContacts.MsgContentType.TEXT;
    }

    public static String getLastMsgTime(long time) {
        if (time == 0L) {
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String tim = simpleDateFormat.format(new Date(time));
        String d = tim.split(" ")[0];
        String t = tim.split(" ")[1];
        String year = d.split("-")[0];
        String month = d.split("-")[1];
        String day = d.split("-")[2];
        String hour = t.split(":")[0];
        String minute = t.split(":")[1];
//        String second = t.split(":")[2];
        Calendar calendar = Calendar.getInstance();
        int yearC = calendar.get(Calendar.YEAR);
//        int monthc = (calendar.get(Calendar.MONTH) + 1);
        int dayc = calendar.get(Calendar.DAY_OF_MONTH);
//        int hourc = calendar.get(Calendar.HOUR_OF_DAY);
//        int minutec = calendar.get(Calendar.MINUTE);
//        int secondc = calendar.get(Calendar.SECOND);
        if (yearC > Integer.parseInt(year)) {
            return String.format("%s年%s月%s日", year, month, day);
        } else if (dayc == Integer.parseInt(day)) {
            return String.format("%s:%s", hour, minute);
        } else if (dayc - Integer.parseInt(day) == 1) {
            return "昨天";
        } else if (dayc - Integer.parseInt(day) == 2) {
            return "前天";
        } else if (dayc > Integer.parseInt(day)) {
            return String.format("%s月%s日", month, day);
        }
        return String.format("%s年%s月%s日", year, month, day);
    }

    public static String getDateSx(int hour) {
        String nihao = "";
        if (hour >= 6 && hour < 8) {
            nihao = "早上";
        } else if (hour >= 8 && hour < 11) {
            nihao = "上午";
        } else if (hour >= 11 && hour < 13) {
            nihao = "中午";
        } else if (hour >= 13 && hour < 18) {
            nihao = "下午";
        } else {
            nihao = "晚上";
        }
        return nihao;
    }

    public static String getChatLastMsgTime(long time) {
        if (time == 0L) {
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String tim = simpleDateFormat.format(new Date(time));
        String d = tim.split(" ")[0];
        String t = tim.split(" ")[1];
        String year = d.split("-")[0];
        String month = d.split("-")[1];
        String day = d.split("-")[2];
        String hour = t.split(":")[0];
        String minute = t.split(":")[1];
//        String second = t.split(":")[2];
        Calendar calendar = Calendar.getInstance();
        int yearC = calendar.get(Calendar.YEAR);
//        int monthc = (calendar.get(Calendar.MONTH) + 1);
        int dayc = calendar.get(Calendar.DAY_OF_MONTH);
//        int hourc = calendar.get(Calendar.HOUR_OF_DAY);
//        int minutec = calendar.get(Calendar.MINUTE);
//        int secondc = calendar.get(Calendar.SECOND);
        if (yearC > Integer.parseInt(year)) {
            return String.format("%s年%s月%s日 %s%s:%s", year, month, day, getDateSx(Integer.parseInt(hour)), hour, minute);
        } else if (dayc == Integer.parseInt(day)) {
            return String.format("%s:%s", hour, minute);
        } else if (dayc - Integer.parseInt(day) == 1) {
            return String.format("%s %s%s:%s", "昨天", getDateSx(Integer.parseInt(hour)), hour, minute);
        } else if (dayc - Integer.parseInt(day) == 2) {
            return String.format("%s %s%s:%s", "前天", getDateSx(Integer.parseInt(hour)), hour, minute);
        } else if (dayc > Integer.parseInt(day)) {
            return String.format("%s月%s日 %s%s:%s", month, day, getDateSx(Integer.parseInt(hour)), hour, minute);
        }
        return String.format("%s年%s月%s日 %s%s:%s", year, month, day, getDateSx(Integer.parseInt(hour)), hour, minute);
    }
}
